﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.UPMS.Model.BusinessPart;
using NHibernate;
using Castle.ActiveRecord;
using System.Data;
using System.Data.SqlClient;

namespace ZDSoft.UPMS.Manager.BusinessPart
{
    public class ScoreManager : ManagerBase<Score>
    {

        public IList<Model.Result> GetProc(int termID, int organizationID)
        {
            ISession session = ActiveRecordBase.holder.CreateSession(typeof(Score));
            IDbConnection conn = session.Connection;
            IDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = "p_getScore";
            cmd.CommandType = CommandType.StoredProcedure;
            IDbDataParameter parameter = cmd.CreateParameter();
            parameter.ParameterName = "@OrganizationID";
            parameter.Value = organizationID;
            cmd.Parameters.Add(parameter);
            IDbDataParameter parameter1 = cmd.CreateParameter();
            parameter1.ParameterName = "@TermID";
            parameter1.Value = termID;
            cmd.Parameters.Add(parameter1);
            IDataReader dr = cmd.ExecuteReader();
            string a = "";
            IList<Model.Result> results = new List<Model.Result>();
            int i = 1;
            while (dr.Read())
            {
                Model.Result r = new Model.Result();
                r.ID = i;
                r.Uname = dr["uName"].ToString();
                r.Cname = dr["cName"].ToString();
                r.Iterm = dr["cTname"].ToString();
                r.InitialScore = 100 - double.Parse(dr["InitialScore"].ToString());
                i++;
                results.Add(r);
            }
            return results;
        }
    }
}
